﻿using Microsoft.AspNetCore.Mvc;
using zhwy.saas.api.Entity.Other;
using zhwy.saas.api.Models;
using zhwy.saas.api.Models.Other.Files;
using zhwy.saas.api.Services.Sinterface;
using zhwy.saas.api.Services.Sinterface.Other;

namespace zhwy.saas.api.Controllers.V1.Other
{
    /// <summary>
    /// 文件服务
    /// </summary>
    [ApiVersion("1.0")]
    public class FilesController : BaseController<FilesEntity>
    {
        private readonly IFilesService  _filesService;
        private readonly ICurrentUserService _currentUserService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="filesService">租户服务</param>
        /// <param name="currentUserService"></param>
        public FilesController(IFilesService  filesService,
            ICurrentUserService currentUserService)
            : base(filesService)
        {
            _filesService = filesService;
            _currentUserService = currentUserService;
        }

        /// <summary>
        /// 添加文件信息
        /// </summary>
        /// <param name="files">文件信息</param>
        /// <param name="sysUploadType"></param>
        /// <returns>添加结果</returns>
        /// <response code="200">添加成功</response>
        /// <response code="400">添加失败</response>
        [HttpPost("upload")]
        public async Task<ApiResponseModel<FilesRes>> Add([FromBody]IFormFile files, [FromQuery]string sysUploadType= "system")
        {
            var userid = _currentUserService.GetUserId();
            var tenantid = _currentUserService.GetTenantId();

            var res = await _filesService.AddFiles(files, userid, tenantid, sysUploadType);

            return GetResponseModel<FilesRes>(res);
        }

    }
}
